package com.pray.client;

import com.pray.protocol.RpcRequest;
import com.pray.protocol.RpcResponse;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.Socket;

/**
 * RpcClientTransfer
 *
 * @author 春江花朝秋月夜
 * @since 2024/1/8 20:34
 */
public class RpcClientTransfer implements Serializable {
    public RpcResponse sendRpcRequest(RpcRequest rpcRequest){
        try {
            Socket socket=new Socket("127.0.0.1",9090);
            //创建对象流
            ObjectOutputStream os=new ObjectOutputStream(socket.getOutputStream());
            ObjectInputStream is=new ObjectInputStream(socket.getInputStream());
            os.writeObject(rpcRequest);
            os.flush();

            RpcResponse rpcResponse= (RpcResponse) is.readObject();
            return rpcResponse;
        } catch (ClassNotFoundException | IOException e) {
            throw new RuntimeException(e);
        }
    }
}
